/*
 * ADC.c
 *
 * Created: 12.09.2012 16:42:28
 *  Author: mariuvi
 */ 
#include <avr/delay.h>

#define OFFSET 0x1400

char ADC_read(int channel)
{
	char receivedByte;
	volatile char* ADC_readByte = (char*) OFFSET;
	
	//selects the channel as single ended and starts the conversion, needs a delay to read consequently
	_delay_ms(1);
	switch (channel)
	{
		case 1:
			ADC_readByte[0] = (char) 0b0100;
			break;
		case 2:
			ADC_readByte[0] = (char) 0b0101;
			break; 
		case 3:
			ADC_readByte[0] = (char) 0b0110;
			break;
		case 4:
			ADC_readByte[0] = (char) 0b0111;
			break;
	}	
	
	_delay_us(40);
	//Reads the byte
	receivedByte = ADC_readByte[0];
	
	return receivedByte;
		
}